<template>
  <el-container>
    <el-header>
      <div class="header-title">健康信息填报后台管理系统</div>
      <el-button type="info" @click="logOut">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu
          :collapse-transition="false"
          :collapse="isCollapse"
          router
          :default-active="activePath"
          class="el-menu-vertical-demo"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF">
          <el-menu-item index="/admin/accountManagement" @click="savePath('/admin/accountManagement')">
            <i class="el-icon-user-solid"></i>
            <span slot="title">账号管理</span>
          </el-menu-item>
          <el-submenu index="/admin/infoManagement" @click="savePath('/admin/infoManagement')">
            <template slot="title">
              <i class="el-icon-document"></i>
              <span>信息管理</span>
            </template>
            <el-menu-item index="/admin/infoManagement/basicInfo" @click="savePath('/admin/infoManagement/basicInfo')"><i class="el-icon-menu"></i>用户信息</el-menu-item>
            <el-menu-item index="/admin/infoManagement/dailyFormInfo" @click="savePath('/admin/infoManagement/dailyFormInfo')"><i class="el-icon-menu"></i>填报情况</el-menu-item>
            <el-menu-item index="/admin/infoManagement/noFillList" @click="savePath('/admin/infoManagement/noFillList')"><i class="el-icon-menu"></i>未填报名单</el-menu-item>
          </el-submenu>
          <el-menu-item index="/admin/dataStatistics" @click="savePath('/admin/dataStatistics')">
            <i class="el-icon-data-analysis"></i>
            <span slot="title">数据统计</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>

import {mapMutations, mapState} from "vuex";

export default {
  name: "Admin",
  data(){
    return{
      //导航栏的收缩情况
      isCollapse:false,
      // activePath:'/admin/index'
    }
  },
  computed:{
    ...mapState(['activePath'])
  },
  created(){
    if(window.localStorage.getItem("activePath")){
      // this.activePath = window.localStorage.getItem("activePath");
      this.changeActivePath(window.localStorage.getItem("activePath"));
    }
    else{
      this.changeActivePath("/admin/index");
    }
    this.$router.push(this.activePath);
  },
  methods:{
    ...mapMutations(['changeActivePath']),
    //切换导航栏的收缩情况
    toggleCollapse(){
      this.isCollapse = !this.isCollapse
    },
    //登出
    logOut(){
      window.localStorage.clear();  //清空localStorage
      this.$router.push("/");
    },
    savePath(path){
      window.localStorage.setItem("activePath",path);
      this.changeActivePath(path);
    }
  }
}
</script>

<style scoped>
  .el-container{
    height: 100%;
  }
  .el-header{
    background-color: #373f41;
    display: flex;
    justify-content: space-between;
    font-size: 20px;
    align-items: center;
    padding: 0 20px 0 0;
  }
  .header-title{
    color:white;
  }
  .el-aside{
    background-color: #333744;
  }
  .toggle-button{
    background-color: #4A5064;
    color:white;
    text-align: center;
    letter-spacing:0.2em;
    font-size: 10px;
    line-height: 24px;
    cursion:pointer;
  }
  .el-main{
    background-color: #eaedf1;
  }
  .el-submenu{
    width: 200px;
  }
  .el-menu-item{
    width: 200px;
  }
</style>
